#!/bin/bash
PROJROOT=`echo $0 | cut -d "/" -f 1`/../
CHROOT=${PROJROOT}/chroot

if [ ! -e ${CHROOT} ]; then
	echo "No chroot, please first create the chroot with create_chroot.sh"
	exit
fi

# mount the needed fs
sudo mount -o bind /proc ${CHROOT}/proc
sudo mount -o bind /sys ${CHROOT}/sys
sudo mount -o bind /dev ${CHROOT}/dev
sudo mount -o bind ${PROJROOT} ${CHROOT}/opt/embtoo
sudo cp /etc/resolv.conf ${CHROOT}/etc/
touch ${CHROOT}/tmp/.embtoo_inside_chroot
# copy the needed files
echo "Entering the embtoo environment"
sudo chroot ${CHROOT} /opt/embtoo/scripts/inside_chroot.sh
echo "Exiting the embtoo environment"
# umount the needed fs
sudo umount ${CHROOT}/opt/embtoo
sudo umount ${CHROOT}/dev
sudo umount ${CHROOT}/sys
sudo umount ${CHROOT}/proc
rm ${CHROOT}/tmp/.embtoo_inside_chroot
